package hjw.com.controller;

import hjw.com.dao.LargeFileMapper;
import hjw.com.entity.LargeFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

@Controller
@RequestMapping("/public")
@SuppressWarnings("all")
public class PublicController {

    @Autowired
    LargeFileMapper largeFileMapper;

    //获取图片信息的头路径
    @GetMapping("/img/{pic}")
    public void getImg(@PathVariable("pic")String pic, HttpServletResponse resp, Model model)throws IOException {
        LargeFile one = largeFileMapper.findOne(pic);
        if (one == null)return;
        byte[] buf = (byte[]) one.getContent();
        OutputStream os = resp.getOutputStream();
        resp.setContentType("image/jpeg");
        os.write(buf);
        os.flush();//刷新资源
    }



}
